package com.itheimaoa.web.action.privilege;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheimaoa.domain.privilege.Employee;
import com.itheimaoa.service.privilege.IEmployeeService;
import com.opensymphony.xwork2.ActionSupport;

@Controller("employeeLogin")
@Scope("prototype")
public class EmployeeLogin extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String username;
	private String password;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Resource
	private IEmployeeService employeeService;

	public String login() {
		return "login";
	}

	public String doLogin() {
		Employee employee = employeeService.checkLogin(this.username, this.password);
		if (employee != null) {
			ServletActionContext.getRequest().getSession().setAttribute("employee", employee);
			return "index";
		}
		return "login";
	}
}
